package com.oa.system.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.joneying.common.annotation.CommonController;
import com.joneying.common.web.response.Resp;
import com.oa.core.BaseController;
import com.oa.core.exception.DataIsEmptyException;
import com.oa.system.dto.ApplyApprovalAddDTO;
import com.oa.system.dto.ApprovalDTO;
import com.oa.system.entity.ApprovalProcessDefine;
import com.oa.system.service.IApplyApprovalService;
import com.oa.system.service.IApprovalProcessDefineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@RestController
@RequestMapping("/process/manage")
@Api(description = "流程管理模块")
public class ProcessManageController extends BaseController {

    @Autowired
    private IApprovalProcessDefineService approvalProcessDefineService;

    @Autowired
    private IApplyApprovalService applyApprovalService;


    @GetMapping("/approvalNode")
    @CommonController
    @Description("查询节点")
    @ApiOperation(value = "查询流程列表")
    public Resp<ApprovalProcessDefine> getApprovalNode(@RequestBody ApplyApprovalAddDTO applyApprovalAddDTO){
//        applyApprovalService.getPlanId(getLoginUserId(), getPlanId)
        return null;
    }

    @GetMapping("/approval/process/list")
    @CommonController
    @Description("查询流程列表")
    @ApiOperation(value = "查询流程列表")
    public Resp<ApprovalProcessDefine> getApprovalProcessList(){
        return new Resp().success(approvalProcessDefineService.selectList(new EntityWrapper()));
    }

    @PostMapping("/approval")
    @CommonController
    @Description("添加审批")
    @ApiOperation(value = "添加审批")
    public Resp addApproval(@RequestBody @Valid ApplyApprovalAddDTO applyApprovalAddDTO){
        return applyApprovalService.addApproval(applyApprovalAddDTO);
    }

    @PutMapping("/approval/audit")
    @CommonController
    @Description("审核")
    @ApiOperation(value = "审核")
    public Resp auditApproval(@RequestBody @Valid ApprovalDTO approvalDTO) throws DataIsEmptyException {
        approvalDTO.setUserId(getLoginUserId());
        return applyApprovalService.audit(approvalDTO);
    }


}
